package ch.fusun.baron.unit;

/**
 * The military unit model
 */
public class Unit {

	private int id;
	private int numberOfUnits;

	/**
	 * Kryonet constructor
	 */
	public Unit() {

	}

	/**
	 * @param id
	 *            The id
	 * @param numberOfUnits
	 *            the number of men in the unit
	 */
	public Unit(int id, int numberOfUnits) {
		this.id = id;
		this.numberOfUnits = numberOfUnits;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Unit other = (Unit) obj;
		if (id != other.id)
			return false;
		return true;
	}

	/**
	 * @return The number of men in the unit
	 */
	public int getNumberOfUnits() {
		return this.numberOfUnits;
	}

	/**
	 * @param casualties
	 *            The men to kill
	 */
	public void kill(int casualties) {
		this.numberOfUnits -= casualties;
	}

	/**
	 * @return Is the unit still there?
	 */
	public boolean isDead() {
		return numberOfUnits <= 0;
	}
}
